/* 
 * File:   main.c
 * Author: Bruno
 *
 */
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>

float vermelho = 1.0f,
      verde = 1.0f,
      azul  = 1.0f;

void display(void) {
/*
    glClear(GL_COLOR_BUFFER_BIT);

    // desenha o triangulo de acordo com a cor selecionada:
    glColor3f(vermelho, verde, azul);

    glBegin(GL_TRIANGLES);
    glVertex2f(-0.5f, -0.5f);
    glVertex2f(0.5f, -0.5f);
    glVertex2f(0.0f, 0.5f);
    glEnd();

    glFlush();
 * 
*/
    
    run();
}

void change(int key, int x, int y) {
    switch (key) {

            //mude a cor para vermelho
        case GLUT_KEY_LEFT:
            vermelho = 1.0f;
            verde = 0.0f;
            azul  = 0.0f;

            glutPostRedisplay();
            break;

            //mude a cor para verde
        case GLUT_KEY_RIGHT:
            vermelho = 0.0f;
            verde = 1.0f;
            azul = 0.0f;

            glutPostRedisplay();
            break;

            // mude a cor para azul
        case GLUT_KEY_UP:
            vermelho = 0.0f;
            verde = 0.0f;
            azul  = 1.0f;

            glutPostRedisplay();
            break;
    }
}

void keyboard(unsigned char key, int x, int y) {
    switch (key) {

            // ESC termina o programa
        case 27:
            exit(0);
            break;
    }
}

void mouse(int key, int x, int y, int z) {
    switch (key) {
        case GLUT_LEFT:
            vermelho = 1.0f;
            verde = 0.5f;
            azul  = 0.0f;

            
            glRotated(0,0.5,0.5,0.5);
            glutPostRedisplay();
            break;

        case GLUT_RIGHT_BUTTON:
            vermelho = 0.0f;
            verde = 1.0f;
            azul  = 1.0f;

            glutPostRedisplay();
            break;
    }
}

void init() {
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}

int main(int argc, char *argv[]) {
    glutInit(&argc, argv);
    glutCreateWindow("Teclado");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutSpecialFunc(change);
    glutMouseFunc(mouse);

    init();

    glutMainLoop();
   
}

